#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char* argv[])
{
    if(argc < 2) {
        printf("errore\n\r");
        return 0;
    }                                    

    if(!strcmp(argv[1], "createlink")) {
        if(argc < 3) {
            printf("errore\n\r");
            return 0;
        }
        char cmd[256];

        snprintf(cmd, sizeof(cmd), "/bin/ln -s /home/projects/%s /home/%s/projects/", argv[2], argv[3]);
                
        if(system(cmd) == -1) {
            perror("system error");
            return 0;
        }

        return 0;
    } if(!strcmp(argv[1], "deletelink")) {
        if(argc < 3) {
            printf("errore\n\r");
            return 0;
        }
        char cmd[256];

        snprintf(cmd, sizeof(cmd), "/usr/bin/unlink /home/%s/projects/%s", argv[3], argv[2]);

        if(system(cmd) == -1) {
            perror("system error");
            return 0;
        }

        return 0;
    } if(!strcmp(argv[1], "addusertoml")) {
        if(argc < 3) {
            printf("errore\n\r");
            return 0;
        }
    
        char cmd[256];
        
        snprintf(cmd, sizeof(cmd), "echo %s|/usr/sbin/add_members -r - %s", argv[3], argv[2]);
        
        if(system(cmd) == -1) {
            perror("system error");
            return 0;
        }
    } if(!strcmp(argv[1], "deluserfromml")) {
        if(argc < 3) {
            printf("errore\n\r");
            return 0;
        }

        char cmd[256];

        snprintf(cmd, sizeof(cmd), "echo %s|/usr/sbin/remove_members -f - %s", argv[3], argv[2]);

        if(system(cmd) == -1) {
            perror("system error");
            return 0;
        }
    }


    
    return 0;
}
